package hust.music.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import hust.music.action.base.ActionBase;
import hust.music.service.PlayListModService;
import hust.music.util.DynamicInfo;
import hust.music.util.Page;

import java.util.*;

/**
 * FindMusicAction
 * 
 * @author Txazo
 * @since 1.0
 */
@Controller
@Scope("session")
public class FindMusicAction extends ActionBase {

	private static final long serialVersionUID = 1L;

	/** 当前页 */
	private int pageNow;
	/** 每页显示数 */
	private int pageSize = 10;
	/** 分页 */
	private Page page;

	/** 标签名称 */
	private String title;

	/** 按时间分页 */
	private List<DynamicInfo> musicByTime = new ArrayList<DynamicInfo>();
	/** 按收听量分页 */
	private List<DynamicInfo> musicByListening = new ArrayList<DynamicInfo>();
	/** 按评分分页 */
	private List<DynamicInfo> musicByMark = new ArrayList<DynamicInfo>();
	/** 按标签分页 */
	private List<DynamicInfo> musicByLabel = new ArrayList<DynamicInfo>();

	@Autowired
	private PlayListModService playListPageModService;

	/**
	 * 按时间查找音乐
	 * 
	 * @return 逻辑视图
	 */
	public String findMusicByTime() {
		int first = (pageNow - 1) * pageSize;
		int length = playListPageModService.findTotalMusic();

		musicByTime = playListPageModService.findMusicByTime(first, this
				.getPageSize());

		page = new Page(this.getPageNow(), this.getPageSize(), length);

		return "findMusicByTime";
	}

	/**
	 * 按收听量查找音乐
	 * 
	 * @return 逻辑视图
	 */
	public String findMusicByListening() {
		int first = (pageNow - 1) * pageSize;
		int length = playListPageModService.findTotalMusic();

		musicByListening = playListPageModService.findMusicByListening(first,
				this.getPageSize());

		page = new Page(this.getPageNow(), this.getPageSize(), length);

		return "findMusicByListening";
	}

	/**
	 * 按评分查找音乐
	 * 
	 * @return 逻辑视图
	 */
	public String findMusicByMark() {
		int first = (pageNow - 1) * pageSize;
		int length = playListPageModService.findTotalMusic();

		musicByMark = playListPageModService.findMusicByMark(first, this
				.getPageSize());

		page = new Page(this.getPageNow(), this.getPageSize(), length);

		return "findMusicByMark";
	}

	/**
	 * 按标签查找音乐
	 * 
	 * @return 逻辑视图
	 */
	public String findMusicByLabel() {
		int first = (pageNow - 1) * pageSize;
		int length = playListPageModService.findTotalMusicByLabel(title);

		musicByLabel = playListPageModService.findMusicByLabel(title, first,
				this.getPageSize());

		page = new Page(this.getPageNow(), this.getPageSize(), length);

		return "findMusicByLabel";
	}

	public List<DynamicInfo> getMusicByTime() {
		return musicByTime;
	}

	public void setMusicByTime(List<DynamicInfo> musicByTime) {
		this.musicByTime = musicByTime;
	}

	public List<DynamicInfo> getMusicByListening() {
		return musicByListening;
	}

	public void setMusicByListening(List<DynamicInfo> musicByListening) {
		this.musicByListening = musicByListening;
	}

	public List<DynamicInfo> getMusicByMark() {
		return musicByMark;
	}

	public void setMusicByMark(List<DynamicInfo> musicByMark) {
		this.musicByMark = musicByMark;
	}

	public int getPageNow() {
		return pageNow;
	}

	public void setPageNow(int pageNow) {
		this.pageNow = pageNow;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public List<DynamicInfo> getMusicByLabel() {
		return musicByLabel;
	}

	public void setMusicByLabel(List<DynamicInfo> musicByLabel) {
		this.musicByLabel = musicByLabel;
	}

}
